using UnityEngine;
using System.Collections;

[AddComponentMenu("Camera-Control/Smooth Look At")]

partial class SmoothLookAt : MonoBehaviour
{

	public Transform target;
	public float damping = 6.0f;
	public bool smooth = true;
	
	void LateUpdate()
	{
		if(target != null)
		{
			if(smooth)
			{
				//Look at, then dampen the rotation
				Quaternion rotation = Quaternion.LookRotation(target.position - transform.position);
				transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping);
			}
			else
			{
				//Just look at
				transform.LookAt(target);
			}
		}
	}
	
	void Start()
	{
		if(rigidbody)
		{
			rigidbody.freezeRotation = true;
		}
	}

}